#include<stdio.h>
int pdsf(int a, int b)
{
    if(a == b) return 0;
    else if((a==0 && (b==2||b==3)) || (a==1&&(b==0||b==3)) || (a==2&&(b==1||b==4)) || (a==3&&(b==2||b==4)) || (a==4&&(b==0||b==1))) return 1;
    else return 2;
}
int main()
{
    int a[205];
    int b[205];
    int scorea = 0;
    int scoreb = 0;
    //freopen("in.txt","r",stdin);
    int n,na,nb;
    scanf("%d %d %d",&n,&na,&nb);
    for(int i = 0; i < na; i++) scanf("%d",&a[i]);
    for(int i = 0; i < nb; i++) scanf("%d",&b[i]);
    for(int i = 0; i < n; i++)
    {
        if(pdsf(a[i%na],b[i%nb]) == 1)
        {
            scorea++;
        } 
        if(pdsf(a[i%na],b[i%nb]) == 2)
        {
            scoreb++;
        }
    }
    printf("%d %d",scorea,scoreb);
}